package com.gr.search;


import com.mysql.jdbc.Connection;

import java.sql.DriverManager;
import java.sql.SQLException;

public class Connector {
	static public Connection connect() throws ClassNotFoundException, SQLException
	{
		Connection con=null;
		try
		{			
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/spindex";
			String username ="root";
			String pw ="";
			con = (Connection) DriverManager.getConnection(url, username, pw);
			System.out.println("Connect succesful");
			return con;
		}
		catch(ClassNotFoundException e)
		{
			if(con!=null) con.close();
			throw e;
			
		}
		catch(SQLException e)
		{
			if(con!=null) con.close();
			throw e;
		}
		finally
		{
//			if(con!=null) con.close();
		}
	}
        
        static public Connection connect2() throws ClassNotFoundException, SQLException
	{
		Connection con=null;
		try
		{
			
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/irsystem?useUnicode=true&characterEncoding=UTF-8";
                        String username ="root";
			String pw ="";
			con=(Connection) DriverManager.getConnection(url, username, pw);
			System.out.println("Connect succesful");
			return con;
		}
		catch(ClassNotFoundException e)
		{
			if(con!=null) con.close();
			throw e;
			
		}
		catch(SQLException e)
		{
			if(con!=null) con.close();
			throw e;
		}
		finally
		{
//			if(con!=null) con.close();
		}
	}
}
